#include <stddef.h>
#include <stdarg.h>
#include "n2types.h"
#ifndef N2BASE_H_789D9CE6C40199EC1F1DF94CC53F3FAC
#define N2BASE_H_789D9CE6C40199EC1F1DF94CC53F3FAC       1

extern int little_endian;

enum N2Excep {
    N2Excep_NoMemory = 1,
};

#define N2_PASS                                         0
#define N2_SUCCESS                                      1
#define N2_ERR                                          -1

int n2base_init();
extern int (*n2print)(const char *format, ...);             // the function like printf(), must be UTF-8 string
extern int (*n2prterr)(const char *format, ...);            // the function like perror(), must be UTF-8 string
extern int (*n2vprint)(const char *format, va_list vargs);  // the function like printf(), must be UTF-8 string
extern int (*n2vprterr)(const char *format, va_list vargs); // the function like perror(), must be UTF-8 string

#define N2_LOCALE_en_US                                 0
#define N2_LOCALE_zh_CN                                 1
#define N2_LOCALE_zh_TW                                 2
#define N2_LOCALE_MAX                                   3

int n2base_get_nlsid();

#define isUTF8Style1(b1)                 ( ((b1)&0x80)==0 )
#define isUTF8Style2(b1,b2)              ( (((b1)&0xE0)==0xC0) && (((b2)&0xC0)==0x80) )
#define isUTF8Style3(b1,b2,b3)           ( (((b1)&0xF0)==0xE0) && (((b2)&0xC0)==0x80) && (((b3)&0xC0)==0x80) )
#define isUTF8Style4(b1,b2,b3,b4)        ( (((b1)&0xF8)==0xF0) && (((b2)&0xC0)==0x80) && (((b3)&0xC0)==0x80) && (((b4)&0xC0)==0x80) )
#define isUTF8Style5(b1,b2,b3,b4,b5)     ( (((b1)&0xFC)==0xF8) && (((b2)&0xC0)==0x80) && (((b3)&0xC0)==0x80) && (((b4)&0xC0)==0x80) && (((b5)&0xC0)==0x80) )
#define isUTF8Style6(b1,b2,b3,b4,b5,b6)  ( (((b1)&0xFE)==0xFC) && (((b2)&0xC0)==0x80) && (((b3)&0xC0)==0x80) && (((b4)&0xC0)==0x80) && (((b5)&0xC0)==0x80) && (((b6)&0xC0)==0x80) )

#define UTF8ToU32CharS1(b1)                ( (unsigned)(b1) )
#define UTF8ToU32CharS2(b1,b2)             ( ((((unsigned)(b1))&0x1F)<<6)  | (((unsigned)(b2))&0x3F) )
#define UTF8ToU32CharS3(b1,b2,b3)          ( ((((unsigned)(b1))&0x0F)<<12) | ((((unsigned)(b2))&0x3F)<<6) | (((unsigned)(b3))&0x3F) )
#define UTF8ToU32CharS4(b1,b2,b3,b4)       ( ((((unsigned)(b1))&0x07)<<18) | ((((unsigned)(b2))&0x3F)<<12) | ((((unsigned)(b3))&0x3F)<<6) | (((unsigned)(b4))&0x3F) )
#define UTF8ToU32CharS5(b1,b2,b3,b4,b5)    ( ((((unsigned)(b1))&0x03)<<24) | ((((unsigned)(b2))&0x3F)<<18) | ((((unsigned)(b3))&0x3F)<<12) | ((((unsigned)(b4))&0x3F)<<6) | (((unsigned)(b5))&0x3F) )
#define UTF8ToU32CharS6(b1,b2,b3,b4,b5,b6) ( ((((unsigned)(b1))&0x01)<<30) | ((((unsigned)(b2))&0x3F)<<24) | ((((unsigned)(b3))&0x3F)<<18) | ((((unsigned)(b4))&0x3F)<<12) | ((((unsigned)(b5))&0x3F)<<6) | (((unsigned)(b6))&0x3F) )

int is_little_endian(void);
#define N2Swap16(x) ((((x)&0xff)<<8) | (((x)>>8)&0xff))
#define N2Swap32(x) ((((x)&0xff)<<24) | ((((x)>>8)&0xff)<<16) | ((((x)>>16)&0xff)<<8) | (((x)>>24)&0xff))
#define N2Swap64(x) ((((x)&0xff)<<56) | ((((x)>>8)&0xff)<<48) | ((((x)>>16)&0xff)<<40) | ((((x)>>24)&0xff)<<32) | ((((x)>>32)&0xff)<<24) | ((((x)>>40)&0xff)<<16) | ((((x)>>48)&0xff)<<8) | (((x)>>56)&0xff))
unsigned short MKLE16(unsigned short v);
unsigned int MKLE32(unsigned int v);
unsigned long long MKLE64(unsigned long long v);


#include "StringPool.h"

// #include "func_crc32.h"
// #include "BLHashTable.h"
// #include "BLStringPool.h"
// #include "BLIO.h"
// #include "BLString.h"
// #include "BLArray.h"

#endif // N2BASE_H_789D9CE6C40199EC1F1DF94CC53F3FAC

